{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import os\n",
    "\n",
    "from datasets import load_dataset\n",
    "\n",
    "humanevalplus = load_dataset(\"evalplus/humanevalplus\", split=\"test\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pprint import pprint\n",
    "\n",
    "pprint(humanevalplus[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset = []\n",
    "for entry in humanevalplus:\n",
    "    tests = entry[\"test\"]\n",
    "\n",
    "    if len(tests) == 0:\n",
    "        continue\n",
    "\n",
    "    new_entry = {\n",
    "        \"problem\": entry[\"prompt\"],\n",
    "        \"solutions\": entry[\"prompt\"] + entry[\"canonical_solution\"],\n",
    "        \"tests\": tests + \"\\n\" + f\"check({entry['entry_point']})\",\n",
    "    }\n",
    "\n",
    "    # This is a broken test case that the offical solution can't pass no matter what.\n",
    "    if \"_poly\" in tests:\n",
    "        continue\n",
    "\n",
    "    dataset.append(new_entry)\n",
    "\n",
    "print(f\"Test dataset size: {len(dataset)}\")\n",
    "\n",
    "output_dir = os.path.abspath(\"../../test/code\")\n",
    "os.makedirs(output_dir, exist_ok=True)\n",
    "\n",
    "output_file = os.path.join(output_dir, \"humanevalplus.json\")\n",
    "with open(output_file, \"w\") as f:\n",
    "    json.dump(dataset, f, indent=4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "rllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
